#!/bin/Rscript

library(agricolae)

#Profits Erro 20%, 0% e -20%
on_100_1 <- read.table("risco_1_5_10/erro_0/on/profits.dat")$V1
#on_100_5 <- read.table("risco_5_10_50/erro_0/on/profits.dat")$V1

op_100_1_0 <- read.table("risco_1_5_10/erro_0/rf/profits.dat")$V1
ut_100_1_0 <- read.table("risco_1_5_10/erro_0/ut/profits.dat")$V1
iosup_100_1_0 <- read.table("risco_1_5_10/erro_0/iosup/profits.dat")$V1
super_100_1_0 <- read.table("risco_1_5_10/erro_0/super/profits.dat")$V1

#op_100_1_20 <- read.table("risco_1_5_10/erro_20/rf/profits.dat")$V1
#ut_100_1_20 <- read.table("risco_1_5_10/erro_20/ut/profits.dat")$V1
#iosup_100_1_20 <- read.table("risco_1_5_10/erro_20/iosup/profits.dat")$V1
#super_100_1_20 <- read.table("risco_1_5_10/erro_20/super/profits.dat")$V1

#op_100_5_20 <- read.table("risco_5_10_50/erro_20/rf/profits.dat")$V1
#ut_100_5_20 <- read.table("risco_5_10_50/erro_20/ut/profits.dat")$V1
#iosup_100_5_20 <- read.table("risco_5_10_50/erro_20/iosup/profits.dat")$V1
#super_100_5_20 <- read.table("risco_5_10_50/erro_20/super/profits.dat")$V1

#op_100_1_m20 <- read.table("risco_1_5_10/erro_m20/rf/profits.dat")$V1
#ut_100_1_m20 <- read.table("risco_1_5_10/erro_m20/ut/profits.dat")$V1
#iosup_100_1_m20 <- read.table("risco_1_5_10/erro_m20/iosup/profits.dat")$V1
#super_100_1_m20 <- read.table("risco_1_5_10/erro_m20/super/profits.dat")$V1

#op_100_5_m20 <- read.table("risco_5_10_50/erro_m20/rf/profits.dat")$V1
#ut_100_5_m20 <- read.table("risco_5_10_50/erro_m20/ut/profits.dat")$V1
#iosup_100_5_m20 <- read.table("risco_5_10_50/erro_m20/iosup/profits.dat")$V1
#super_100_5_m20 <- read.table("risco_5_10_50/erro_m20/super/profits.dat")$V1

#Hipótese nula ON=RF=UT=SUPER=IOSUP

paste("Anova 0% 1_5_10%")
valores = data.frame(on_100_1, op_100_1_0, ut_100_1_0, iosup_100_1_0, super_100_1_0)
valores=stack(valores) 
oneway.test(values ~ ind, data=valores, var.equal=T)
r1=aov(values~ind,data=valores)	
scheffe.test(r1,"ind", group=FALSE)
qf(.95, 3, 276)

#paste("Anova 0% 5_10_50%")
#valores = data.frame(on_100_5, op_100_5_0, ut_100_5_0, iosup_100_5_0, super_100_5_0)
#valores=stack(valores) 
#oneway.test(values ~ ind, data=valores, var.equal=T)
#r1=aov(values~ind,data=valores)	
#scheffe.test(r1,"ind", group=FALSE)
#qf(.95, 3, 276)

#paste("Anova +20% 1_5_10%")
#valores = data.frame(on_100_1, op_100_1_20, ut_100_1_20, iosup_100_1_20, super_100_1_20)
#valores=stack(valores) 
#oneway.test(values ~ ind, data=valores, var.equal=T)
#r1=aov(values~ind,data=valores)	
#scheffe.test(r1,"ind", group=FALSE)
#qf(.95, 3, 276)

#paste("Anova +20% 5_10_50%")
#valores = data.frame(on_100_5, op_100_5_20, ut_100_5_20, iosup_100_5_20, super_100_5_20)
#valores=stack(valores)
#oneway.test(values ~ ind, data=valores, var.equal=T)
#r1=aov(values~ind,data=valores)
#scheffe.test(r1,"ind", group=FALSE)
#qf(.95, 3, 276)

# valor oneway.test é maior que a distribuição F => aceita que há diferença

#paste("Anova -20% 1_5_10%")
#valores = data.frame(on_100_1, op_100_1_m20, ut_100_1_m20, iosup_100_1_m20, super_100_1_m20)
#valores=stack(valores) 
#oneway.test(values ~ ind, data=valores, var.equal=T)
#r1=aov(values~ind,data=valores)	
#scheffe.test(r1,"ind", group=FALSE)
#qf(.95, 3, 276)

#paste("Anova -20% 5_10_50%")
#valores = data.frame(on_100_5, op_100_5_m20, ut_100_5_m20, iosup_100_5_m20, super_100_5_m20)
#valores=stack(valores)
#oneway.test(values ~ ind, data=valores, var.equal=T)
#r1=aov(values~ind,data=valores)
#scheffe.test(r1,"ind", group=FALSE)
#qf(.95, 3, 276)

# valor oneway.test é maior que a distribuição F => aceita que há diferença


#Pairwise-t.test

paste("Pairwise 0% 1_5_10%: alt = diff, less, greater")
valores = data.frame(op=op_100_1_0, ut=ut_100_1_0, on=on_100_1, iosup=iosup_100_1_0, super=super_100_1_0)
valores = stack(valores)
attach(valores)
pairwise.t.test(values, ind, p.adj="bonf", alternative="two.sided", paired=TRUE)
pairwise.t.test(values, ind, p.adj="bonf", alternative="less", paired=TRUE)
pairwise.t.test(values, ind, p.adj="bonf", alternative="greater", paired=TRUE)

#paste("Pairwise 0% 5_10_50%")
#valores = data.frame(op=op_100_5_0, ut=ut_100_5_0, on=on_100_5, iosup=iosup_100_5_0, super=super_100_5_0)
#valores = stack(valores)
#attach(valores)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="two.sided", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="less", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="greater", paired=TRUE)

#paste("Pairwise +20% 1_5_10%: alt = diff, less, greater")
#valores = data.frame(op=op_100_1_20, ut=ut_100_1_20, on=on_100_1, iosup=iosup_100_1_20, super=super_100_1_20)
#valores = stack(valores)
#attach(valores)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="two.sided", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="less", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="greater", paired=TRUE)

#paste("Pairwise +20% 5_10_50%")
#valores = data.frame(op=op_100_5_20, ut=ut_100_5_20, on=on_100_5, iosup=iosup_100_5_20, super=super_100_5_20)
#valores = stack(valores)
#attach(valores)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="two.sided", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="less", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="greater", paired=TRUE)

#paste("Pairwise -20% 1_5_10%")
#valores = data.frame(op=op_100_1_m20, ut=ut_100_1_m20, on=on_100_1, iosup=iosup_100_1_m20, super=super_100_1_m20)
#valores = stack(valores)
#attach(valores)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="two.sided", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="less", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="greater", paired=TRUE)

#paste("Pairwise -20% 5_10_50%")
#valores = data.frame(op=op_100_5_m20, ut=ut_100_5_m20, on=on_100_5, iosup=iosup_100_5_m20, super=super_100_5_m20)
#valores = stack(valores)
#attach(valores)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="two.sided", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="less", paired=TRUE)
#pairwise.t.test(values, ind, p.adj="bonf", alternative="greater", paired=TRUE)

